/* GUI CONVERTED from rcshwbb2.p (converter v1.75) Sat Aug 12 23:02:26 2000 */
/* rcshwbb2.p - Shipper Workbench Consume Requirements Subprogram             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*V8:ConvertMode=Maintenance                                                  */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                       */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96      BY: TSI *K005*               */
/* REVISION: 8.6    LAST MODIFIED: 11/21/96      BY: *K003* Vinay Nayak-Sujir */
/* REVISION: 8.6    LAST MODIFIED: 12/03/96      BY: *K02T* Chris Theisen     */
/* REVISION: 8.6    LAST MODIFIED: 12/06/96      BY: *K02F* Chris Theisen     */
/* REVISION: 8.6    LAST MODIFIED: 10/13/97      BY: *K0JC* John Worden       */
/* REVISION: 8.6    LAST MODIFIED: 11/11/97      BY: *K18W* Suresh Nayak      */

/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane            */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 8.6E   LAST MODIFIED: 06/01/98   BY: *K1NF* Niranjan R.          */
/* REVISION: 8.6E   LAST MODIFIED: 07/22/98   BY: *J2M7* Niranjan R.          */
/* REVISION: 8.6E   LAST MODIFIED: 12/15/98   BY: *K1YG* Seema Varma          */
/* REVISION: 8.6E   LAST MODIFIED: 06/16/99   BY: *K214* Kedar Deherkar       */
/* REVISION: 8.6E   LAST MODIFIED: 08/06/99   BY: *K21H* Santosh Rao          */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1    LAST MODIFIED: 04/24/00   BY: *L0PR* Kedar Deherkar       */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* myb                  */

         {mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcshwbb2_p_1 "Comments"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

         /*INPUT PARAMETERS*/
         define input parameter abs_recid as recid no-undo.
         define input parameter absship_recid as recid no-undo.

         /*LOCAL VARIABLES */
         define variable peg_qty like absr_qty no-undo.
         define variable open_qty like absr_qty no-undo.
         define variable cum_open_qty as decimal no-undo.
         define variable cum_all_qty as decimal no-undo.
         define variable ship_cmplt as decimal no-undo.
         define variable item_all_qty as decimal no-undo.
         define variable shipid as character no-undo.

         define variable first_column as character no-undo.
         define variable disp_line as character no-undo.
         define variable gwt_um as character no-undo.
         define variable cnsm_req as logical no-undo.
/*K18W** /*K003*/ define variable pick_qty like sod_qty_pick no-undo.   */
/*K003*/ define variable cmmts like mfc_logical label {&rcshwbb2_p_1} no-undo.
/*K0JC*/ define variable part_order like abs_order no-undo.
/*K0JC*/ define variable part_order_line like abs_line no-undo.
/*K1NF*/ define variable l_abs_pick_qty like sod_qty_pick no-undo.
/*J2M7*/ define variable l_abs_tare_wt  like abs_nwt no-undo.
/*J2M7*/ define variable l_twt_um       as character no-undo.
/*K214*/ define variable l_first        as logical initial true no-undo.
/*K214*/ define variable l_recid        as recid   no-undo.
/*K214*/ define variable l_curr_recid   as recid   no-undo.
/*K214*/ define variable l_fst_cum_open as decimal initial 0 no-undo.
/*K214*/ define variable l_fst_cum_all  as decimal initial 0 no-undo.
/*K214*/ define variable l_prev_openqty like absr_qty        no-undo.
/*L0PR*/ define variable cancel_bo      like mfc_logical     no-undo.
/*K214*/ define query    q_schd_det     for  schd_det scrolling.

         /*WORKFILES*/
         define workfile prior no-undo
            field prior_open_qty as decimal
            field prior_all_qty as decimal.

         /*BUFFERS*/
         define buffer ship_line for abs_mstr.

         /*CONTAINER WORKBENCH FORMS*/
         {rcshwbfm.i}

         find abs_mstr
            where recid(abs_mstr) = absship_recid
            no-lock.

/*K1YG** shipid = substring(abs_id,1,8). */
/*K1YG*/ shipid =  abs_id.

         find abs_mstr
            where recid(abs_mstr) = abs_recid
            no-lock.

         find so_mstr
            where so_nbr = abs_order
            no-lock.

         find sod_det
            where sod_nbr = abs_order
              and sod_line = integer(abs_line)
            no-lock.

         ship_cmplt = if so_ship_cmplt = 0
                         then 100 else so_ship_cmplt.

         for each absr_det
            where absr_shipfrom = abs_shipfrom
              and absr_id = abs_id
              and not absr_cnfrmd
            no-lock:

            peg_qty = peg_qty + absr_qty.

         end.

/*K214** BEGIN DELETE **
 *       display
 *          abs_qty
 *          peg_qty
 *       with frame peg-1.
 *K214** END DELETE */

         pause 0.

         MAIN:
         do transaction on endkey undo:
/*GUI*/ if global-beam-me-up then undo, leave.

            clear frame peg-2 all no-pause.
/*K214**    view frame peg-2. */

/*K214**    BEGIN DELETE **
 *          find first schd_det
 *             where schd_type     = 3
 *               and schd_nbr      = sod_nbr
 *               and schd_line     = sod_line
 *               and schd_rlse_id  = sod_curr_rlse_id[3]
 *             exclusive-lock no-error.
 *K214**    END DELETE */

/*K214*/    open query q_schd_det for each schd_det exclusive-lock
/*K214*/                             where schd_type    = 3        and
/*K214*/                                   schd_nbr     = sod_nbr  and
/*K214*/                                   schd_line    = sod_line and
/*K214*/                                   schd_rlse_id = sod_curr_rlse_id[3].
/*GUI*/ if global-beam-me-up then undo, leave.

/*K214*/    get first q_schd_det exclusive-lock.

            if not available schd_det then
            do:
               {mfmsg.i 1532 4}
               return.
            end.

            repeat while available schd_det
               with frame peg-2:

/*K214*/       /* THE BELOW SECTION MOVED TO INTERNAL PROCEDURE P-OPENQTY */
/*K214**       BEGIN DELETE **
 *             item_all_qty = 0.
 *
 *             if not so_cum_acct then
 *             for each ship_line
 *                where ship_line.abs_shipfrom  = abs_mstr.abs_shipfrom
 *                  and ship_line.abs_par_id    = abs_mstr.abs_par_id
 *                  and ship_line.abs_order     = abs_mstr.abs_order
 *                  and ship_line.abs_line      = abs_mstr.abs_line
 *                no-lock,
 *                each absr_det
 *                where absr_shipfrom   = ship_line.abs_shipfrom
 *                  and absr_id         = ship_line.abs_id
 *                  and absr_type       = schd_type
 *                  and absr_nbr        = schd_nbr
 *                  and absr_line       = schd_line
 *                  and absr_rlse_id    = schd_rlse_id
 *                  and absr_date       = schd_date
 *                  and absr_time       = schd_time
 *                  and absr_interval   = schd_interval
 *                  and absr_reference  = schd_reference
 *                  and not absr_cnfrmd
 *                no-lock:
 *
 *                item_all_qty = item_all_qty + absr_qty.
 *             end.
 *
 *             assign
 *                open_qty     = max(schd_discr_qty -
 *                                   schd_all_qty - schd_ship_qty,0)
 *                open_qty     = if (schd_all_qty - item_all_qty +
 *                                   schd_ship_qty) /
 *                                   schd_discr_qty * 100 >= ship_cmplt
 *                                   then 0 else open_qty
 *                open_qty     = if so_cum_acct
 *                                  then max(schd_cum_qty - sod_cum_qty[1] -
 *                                     cum_open_qty - cum_all_qty -
 *                                     schd_all_qty,0)
 *                                  else open_qty
 *K214**       END DELETE */

/*K214*/       run p-openqty.
/*K214*/       assign
                  cum_open_qty = cum_open_qty + open_qty
                  cum_all_qty  = cum_all_qty + schd_all_qty.

               if available schd_det then
                  find absr_det
/*K214**             where absr_id         = abs_id */
/*K214*/             where absr_shipfrom   = abs_shipfrom
/*K214*/               and absr_id         = abs_id
                       and absr_type       = schd_type
                       and absr_nbr        = schd_nbr
                       and absr_line       = schd_line
                       and absr_rlse_id    = schd_rlse_id
                       and absr_date       = schd_date
                       and absr_time       = schd_time
                       and absr_interval   = schd_interval
                       and absr_reference  = schd_reference
                     no-lock no-error.

/*K214*/          if available absr_det or
/*K214*/             open_qty <> 0 then
/*K214*/          do:
                     display
                        schd_date
                        schd_time
                        schd_interval
                        schd_reference
                        open_qty
                        if available absr_det then absr_qty else 0 @ absr_qty.

/*K214*/             /* OBTAINING THE RECID OF THE FIRST RECORD BEING   */
/*K214*/             /* DISPLAYED, SO THAT IN THE END OF THIS LOOP, THE */
/*K214*/             /* CURSOR IS POSITIONED AT THE CORRECT RECORD      */
/*K214*/             if l_first then
/*K214*/             do:
/*K214*/                assign
/*K214*/                   l_recid        = recid(schd_det)
/*K214*/                   l_first        = false
/*K214*/                   l_fst_cum_open = cum_open_qty - open_qty
/*K214*/                   l_fst_cum_all  = cum_all_qty  - schd_all_qty.
/*K214*/                display
/*K214*/                   abs_qty
/*K214*/                   peg_qty
/*K214*/                with frame peg-1.
/*K214*/             end.

                     if frame-line(peg-2) = frame-down(peg-2) then
                        leave.

                     down 1.
/*K214*/          end. /* IF AVAILABLE ABSR_DET OR OPEN_QTY <> 0 */

/*K214**       BEGIN DELETE **
 *             find next schd_det
 *                where schd_type     = 3
 *                  and schd_nbr      = sod_nbr
 *                  and schd_line     = sod_line
 *                  and schd_rlse_id  = sod_curr_rlse_id[3]
 *                exclusive-lock no-error.
 *K214**       END DELETE */

/*K214*/          get next q_schd_det exclusive-lock.

            end. /* repeat with frame peg-2 */

/*K214*/    if l_first then
/*K214*/    do:
/*K214*/       /* THERE ARE NO OPEN REQUIREMENTS FOR THIS SCHEDULE ORDER */
/*K214*/       {mfmsg.i 2985 1}
/*K214*/       leave main.
/*K214*/    end. /* IF L_FIRST THEN */

            up frame-line(peg-2) - 1 with frame peg-2.

/*K214**    BEGIN DELETE **
 *          find first schd_det
 *             where schd_type     = 3
 *               and schd_nbr      = sod_nbr
 *               and schd_line     = sod_line
 *               and schd_rlse_id  = sod_curr_rlse_id[3]
 *             exclusive-lock no-error.
 *K214**    END DELETE */

/*K214*/    /* FINDING THE RECORD THAT WAS ACTUALLY DISPLAYED FIRST */
/*K214*/    if l_recid <> ? then
/*K214*/       reposition q_schd_det to recid l_recid.
/*K214*/       get next q_schd_det exclusive-lock.

            create prior.
            assign
               prior_all_qty = if available schd_det
                                  then schd_all_qty else 0
/*K214**       cum_all_qty   = 0  */
/*K214**       cum_open_qty  = 0. */
/*K214*/       cum_all_qty   = l_fst_cum_all
/*K214*/       cum_open_qty  = l_fst_cum_open.

            DETAIL1:
            repeat with frame peg-2:
/*GUI*/ if global-beam-me-up then undo, leave.


               display
                  peg_qty
               with frame peg-1.

/*K214*/       /* THE BELOW SECTION MOVED TO INTERNAL PROCEDURE P-OPENQTY */
/*K214**       BEGIN DELETE **
 *             item_all_qty = 0.
 *
 *             if not so_cum_acct then
 *             for each ship_line
 *                where ship_line.abs_shipfrom  = abs_mstr.abs_shipfrom
 *                  and ship_line.abs_par_id    = abs_mstr.abs_par_id
 *                  and ship_line.abs_order     = abs_mstr.abs_order
 *                  and ship_line.abs_line      = abs_mstr.abs_line
 *                no-lock,
 *                each absr_det
 *                where absr_shipfrom   = ship_line.abs_shipfrom
 *                  and absr_id         = ship_line.abs_id
 *                  and absr_type       = schd_type
 *                  and absr_nbr        = schd_nbr
 *                  and absr_line       = schd_line
 *                  and absr_rlse_id    = schd_rlse_id
 *                  and absr_date       = schd_date
 *                  and absr_time       = schd_time
 *                  and absr_interval   = schd_interval
 *                  and absr_reference  = schd_reference
 *                  and not absr_cnfrmd
 *                no-lock:
 *
 *                item_all_qty = item_all_qty + absr_qty.
 *             end.
 *
 *             assign
 *                open_qty = max(schd_discr_qty - schd_all_qty -
 *                              schd_ship_qty,0)
 *                open_qty = if (schd_all_qty - item_all_qty + schd_ship_qty) /
 *                              schd_discr_qty * 100 >= ship_cmplt
 *                              then 0 else open_qty
 *                open_qty = if so_cum_acct
 *                              then max(schd_cum_qty - sod_cum_qty[1] -
 *                                 cum_open_qty - cum_all_qty - schd_all_qty,0)
 *                              else open_qty.
 *K214**       END DELETE */
/*K214*/       run p-openqty.

               if available schd_det then
/*K214*/       do:
                  find absr_det
/*K214**             where absr_id        = abs_id */
/*K214*/             where absr_shipfrom  = abs_shipfrom
/*K214*/               and absr_id        = abs_id
                       and absr_type      = schd_type
                       and absr_nbr       = schd_nbr
                       and absr_line      = schd_line
                       and absr_rlse_id   = schd_rlse_id
                       and absr_date      = schd_date
                       and absr_time      = schd_time
                       and absr_interval  = schd_interval
                       and absr_reference = schd_reference
                     exclusive-lock no-error.

/*K214*/          l_curr_recid = recid(schd_det).
/*K214*/       end. /* IF AVAILABLE SCHD_DET */

/*K214*/       if available absr_det or
/*K214*/          open_qty <> 0 then
                  display
                     schd_date      when (available schd_det)
                     schd_time      when (available schd_det)
                     schd_interval  when (available schd_det)
                     schd_reference when (available schd_det)
                     if available schd_det then open_qty else 0 @ open_qty
                     if available absr_det then absr_qty else 0 @ absr_qty.

               prompt-for
                  absr_qty
/*K02T*        go-on(F9 cursor-up F5 cursor-down page-up page-down). */
/*K21H** /*K02T*/       go-on(F9 cursor-up F5 cursor-down).          */
/*K21H*/       go-on(F9 cursor-up F5 cursor-down F4 end-error).

/*K02T*        REARRANGE CODE - BEGIN */
               /*****************************************************/
               /* ABSR_QTY ENTERED                                  */
               /*****************************************************/
               if absr_qty entered then
               do:

/*K21H*/          /* THE CHECKING OF PEGGED QUANTITY WITH SHIPPED QUANTITY */
/*K21H*/          /* WILL NOT BE DONE FOR EACH CONSUME REQUIREMENT LINE.   */
/*K21H*/          /* IT WILL BE DONE ONLY WHEN THE USER EXISTS FROM THE    */
/*K21H*/          /* CONSUME REQUIREMENT FRAME                             */

/*K21H** BEGIN DELETE **
 *                if peg_qty -
 *                   (if available absr_det then absr_qty else 0) +
 *                   input absr_qty > abs_qty then
 *                do:
 *
 *                   {mfmsg.i 1530 3}
 *                   undo, retry DETAIL1.
 *                end.
 *K21H** END DELETE */

                  if input absr_qty > (open_qty +
                     (if available absr_det then absr_qty else 0)) then
                  do:
                     {mfmsg.i 1531 3}
                     undo, retry DETAIL1.
                  end.

                  if not available absr_det
                     and input absr_qty > 0 then
                  do:
                     create absr_det.
                     assign
                        absr_shipfrom   = abs_shipfrom
                        absr_id         = abs_id
                        absr_type       = schd_type
                        absr_nbr        = schd_nbr
                        absr_line       = schd_line
                        absr_rlse_id    = schd_rlse_id
                        absr_date       = schd_date
                        absr_time       = schd_time
                        absr_interval   = schd_interval
                        absr_reference  = schd_reference
                        absr_qty        = input absr_qty
                        absr_ship_id    = shipid
                        schd_all_qty    = schd_all_qty + absr_qty
                        prior_all_qty   = schd_all_qty
                        peg_qty         = peg_qty + absr_qty.
                        item_all_qty    = item_all_qty + absr_qty
                     .

                  end. /* if not available absr_det */

                  else
                  if available absr_det
                     and input absr_qty = 0 then
                  do:
                     assign
                        schd_all_qty  = max(schd_all_qty - absr_qty,0)
                        prior_all_qty = schd_all_qty
                        peg_qty       = max(peg_qty - absr_qty,0)
                    item_all_qty  = item_all_qty - absr_qty
             .

                     delete absr_det.
                  end.

                  else
                  if available absr_det then
                  assign
                     schd_all_qty  = schd_all_qty - absr_qty + input absr_qty
                     prior_all_qty = schd_all_qty
                     peg_qty       = peg_qty - absr_qty + input absr_qty
                     item_all_qty  = item_all_qty - absr_qty + input absr_qty
                     absr_qty.

                  assign
                     open_qty = max(schd_discr_qty - schd_all_qty -
                                   schd_ship_qty,0)
                     open_qty = if (schd_all_qty - item_all_qty +
                   schd_ship_qty) /
                                   schd_discr_qty * 100 >= ship_cmplt
                                   then 0 else open_qty
                     open_qty = if so_cum_acct
                                   then max(schd_cum_qty - sod_cum_qty[1] -
                                      cum_open_qty - cum_all_qty -
                      schd_all_qty,0)
                                   else open_qty.

          display
             open_qty.
                  pause 0.

               end. /* absr_qty entered */
/*K02T*        REARRANGE CODE - END */

               /*****************************************************/
               /* CURSOR-UP                                         */
               /*****************************************************/
               if lastkey = keycode("F9")
                  or lastkey = keycode("CURSOR-UP") then
               do:

/*K214**          BEGIN DELETE **
 *                find prev schd_det
 *                   where schd_type     = 3
 *                     and schd_nbr      = sod_nbr
 *                     and schd_line     = sod_line
 *                     and schd_rlse_id  = sod_curr_rlse_id[3]
 *                   exclusive-lock no-error.
 *K214**          END DELETE */

/*K214*/          get prev q_schd_det exclusive-lock.

                  if available schd_det then
                  do:
/*K214*/             /* POSITIONING CURSOR TO PREVIOUS RECORD THAT WAS */
/*K214*/             /* ACTUALLY DISPLAYED                             */
/*K214*/             repeat while available schd_det:
/*K214*/                assign
/*K214*/                   cum_all_qty    = cum_all_qty  - schd_all_qty
/*K214*/                   cum_open_qty   = cum_open_qty - prior_open_qty
/*K214*/                   l_prev_openqty = open_qty.

/*K214*/                /* FINDING OPEN QTY FOR THE PREVIOUS RECORD OBTAINED */
/*K214*/                run p-openqty.

/*K214*/                for first absr_det
/*K214*/                   fields(absr_cnfrmd absr_date absr_id absr_interval
/*K214*/                          absr_line absr_nbr absr_qty absr_reference
/*K214*/                          absr_rlse_id absr_shipfrom absr_ship_id
/*K214*/                          absr_time absr_type)
/*K214*/                   where absr_shipfrom  = abs_shipfrom  and
/*K214*/                         absr_id        = abs_id        and
/*K214*/                         absr_type      = schd_type     and
/*K214*/                         absr_nbr       = schd_nbr      and
/*K214*/                         absr_line      = schd_line     and
/*K214*/                         absr_rlse_id   = schd_rlse_id  and
/*K214*/                         absr_date      = schd_date     and
/*K214*/                         absr_time      = schd_time     and
/*K214*/                         absr_interval  = schd_interval and
/*K214*/                         absr_reference = schd_reference
/*K214*/                   no-lock:
/*K214*/                end. /* FOR FIRST ABSR_DET */

/*K214*/                if available absr_det or
/*K214*/                   open_qty <> 0 then
/*K214*/                do:
/*K214**                   up 1. */
/*K214*/                   up 1 with frame peg-2.

/*K214*/                   /* MOVED THIS CODE ABOVE                         */
/*K214**                   assign                                           */
/*K214**                      cum_all_qty  = cum_all_qty - schd_all_qty     */
/*K214**                      cum_open_qty = cum_open_qty - prior_open_qty. */

                           delete prior.
                           find prev prior.
/*K214*/                   leave.
/*K214*/                end. /* IF AVAILABLE ABSR_DET OR OPEN_QTY <> 0 */
/*K214*/                else do:
/*K214*/                   assign
/*K214*/                      cum_all_qty  = cum_all_qty  + schd_all_qty
/*K214*/                      cum_open_qty = cum_open_qty + prior_open_qty
/*K214*/                      open_qty     = l_prev_openqty.
/*K214*/                end. /* ELSE DO */

/*K214*/                get prev q_schd_det exclusive-lock.

/*K214*/                if not available schd_det then
/*K214*/                do:
/*K214*/                   /* BEGINNING OF FILE */
/*K214*/                   {mfmsg.i 21 1}
/*K214*/                   reposition q_schd_det to recid l_curr_recid .
/*K214*/                   get next q_schd_det exclusive-lock.
/*K214*/                   leave.
/*K214*/                end. /* IF NOT AVAIL SCHD_DET */
/*K214*/             end. /* REPEAT */
                  end. /* IF AVAILABLE SCHD_DET */
                  else
                  do:
                     {mfmsg.i 21 1} /* BEGINNING OF FILE */
/*K214**              BEGIN DELETE **
 *                    find first schd_det
 *                      where schd_type     = 3
 *                        and schd_nbr      = sod_nbr
 *                        and schd_line     = sod_line
 *                        and schd_rlse_id  = sod_curr_rlse_id[3]
 *                      exclusive-lock no-error.
 *K214**              END DELETE */

/*K214*/              reposition q_schd_det to recid l_curr_recid .
/*K214*/              get next q_schd_det exclusive-lock.

                  end. /* ELSE   */
               end. /* CURSOR-UP */

               /*****************************************************/
               /* CURSOR DOWN                                       */
               /*****************************************************/
               else
               if lastkey = keycode("F10")
                  or lastkey = keycode("CURSOR-DOWN")
/*K02T*/          or lastkey = keycode("RETURN") then
               do:

/*K214**          BEGIN DELETE **
 *                find next schd_det
 *                   where schd_type     = 3
 *                     and schd_nbr      = sod_nbr
 *                     and schd_line     = sod_line
 *                     and schd_rlse_id  = sod_curr_rlse_id[3]
 *                   exclusive-lock no-error.
 *K214**          END DELETE */

/*K214*/          get next q_schd_det exclusive-lock.

                  if available schd_det then
                  do:
/*K214*/             /* POSITIONING CURSOR TO NEXT RECORD THAT WAS */
/*K214*/             /* ACTUALLY DISPLAYED                         */
/*K214*/             repeat while available schd_det:
/*K214*/                assign
/*K214*/                   cum_all_qty    = cum_all_qty  + prior_all_qty
/*K214*/                   cum_open_qty   = cum_open_qty + open_qty
/*K214*/                   l_prev_openqty = open_qty.

/*K214*/                /* FINDING OPEN QTY FOR THE NEXT RECORD OBTAINED */
/*K214*/                run p-openqty.

/*K214*/                for first absr_det
/*K214*/                   fields(absr_cnfrmd absr_date absr_id absr_interval
/*K214*/                          absr_line absr_nbr absr_qty absr_reference
/*K214*/                          absr_rlse_id absr_shipfrom absr_ship_id
/*K214*/                          absr_time absr_type)
/*K214*/                   where absr_shipfrom  = abs_shipfrom  and
/*K214*/                         absr_id        = abs_id        and
/*K214*/                         absr_type      = schd_type     and
/*K214*/                         absr_nbr       = schd_nbr      and
/*K214*/                         absr_line      = schd_line     and
/*K214*/                         absr_rlse_id   = schd_rlse_id  and
/*K214*/                         absr_date      = schd_date     and
/*K214*/                         absr_time      = schd_time     and
/*K214*/                         absr_interval  = schd_interval and
/*K214*/                         absr_reference = schd_reference
/*K214*/                   no-lock:
/*K214*/                end. /* FOR FIRST ABSR_DET */

/*K214*/                if available absr_det or
/*K214*/                   open_qty <> 0 then
/*K214*/                do:

/*K214**                   down 1. */
/*K214*/                   down 1 with frame peg-2.

/*K214*/                   /* MOVED THIS CODE ABOVE                        */
/*K214**                   assign                                          */
/*K214**                      cum_all_qty    = cum_all_qty + prior_all_qty */
/*K214**                      cum_open_qty   = cum_open_qty + open_qty.    */

                           create prior.
                           assign
/*K214**                      prior_open_qty = open_qty */
/*K214*/                      prior_open_qty = l_prev_openqty
                              prior_all_qty  = schd_all_qty.

/*K214*/                   leave.
/*K214*/                end. /* IF AVAILABLE ABSR_DET OR OPEN_QTY <> 0 */
/*K214*/                else do:
/*K214*/                   assign
/*K214*/                      cum_all_qty  = cum_all_qty  - prior_all_qty
/*K214*/                      cum_open_qty = cum_open_qty - open_qty
/*K214*/                      open_qty     = l_prev_openqty.
/*K214*/                end. /* ELSE DO */

/*K214*/                get next q_schd_det exclusive-lock.

/*K214*/                if not available schd_det then
/*K214*/                do:
/*K214*/                   /* END OF FILE */
/*K214*/                   {mfmsg.i 20 1}
/*K214*/                   reposition q_schd_det to recid l_curr_recid.
/*K214*/                   get next q_schd_det exclusive-lock.
/*K214*/                   leave.
/*K214*/                end. /* IF NOT AVAILABLE SCHD_DET */
/*K214*/             end. /* REPEAT */
/*K214*/          end. /* IF AVAILABLE SCHD_DET */
                  else
                  do:
                     {mfmsg.i 20 1} /* END OF FILE */
/*K214**             BEGIN DELETE **
 *                   find last schd_det
 *                      where schd_type     = 3
 *                        and schd_nbr      = sod_nbr
 *                        and schd_line     = sod_line
 *                        and schd_rlse_id  = sod_curr_rlse_id[3]
 *                      exclusive-lock no-error.
 *K214**             END DELETE */

/*K214*/             reposition q_schd_det to recid l_curr_recid.
/*K214*/             get next q_schd_det exclusive-lock.
                  end.
               end. /* CURSOR-DOWN */

/*K21H*/       else if lastkey = keycode("F4")
/*K21H*/          or keyfunction(lastkey) = "END-ERROR"
/*K21H*/          or keyfunction(lastkey) = "END-KEY" then
/*K21H*/       do:
/*K21H*/          if peg_qty > abs_qty then
/*K21H*/          do:
/*K21H*/             {mfmsg.i 1652 3}
/*K21H*/             undo DETAIL1, retry DETAIL1.
/*K21H*/          end. /* IF PEG_QTY > ABS_QTY  */
/*K21H*/          else undo DETAIL1, leave DETAIL1.
/*K21H*/       end. /* ELSE IF LASTKEY = KEYCODE("F4") OR .. */

/*K02T*        REARRANGE CODE - BEGIN
.              /*****************************************************/
.              /* ABSR_QTY ENTERED                                  */
.              /*****************************************************/
.              else
.              if absr_qty entered then
.              do:
.
.                 if peg_qty -
.                    (if available absr_det then absr_qty else 0) +
.                    input absr_qty > abs_qty then
.                 do:
.                    {mfmsg.i 1530 3}
.                    undo, retry DETAIL1.
.                 end.
.
.                 if input absr_qty > (open_qty +
.                    (if available absr_det then absr_qty else 0)) then
.                 do:
.                    {mfmsg.i 1531 3}
.                    undo, retry DETAIL1.
.                 end.
.
.                 if not available absr_det
.                    and input absr_qty > 0 then
.                 do:
.                    create absr_det.
.                    assign
.                       absr_shipfrom   = abs_shipfrom
.                       absr_id         = abs_id
.                       absr_type       = schd_type
.                       absr_nbr        = schd_nbr
.                       absr_line       = schd_line
.                       absr_rlse_id    = schd_rlse_id
.                       absr_date       = schd_date
.                       absr_time       = schd_time
.                       absr_interval   = schd_interval
.                       absr_reference  = schd_reference
.                       absr_qty        = input absr_qty
.                       absr_ship_id    = shipid
.                       schd_all_qty    = schd_all_qty + absr_qty
.                       prior_all_qty   = schd_all_qty
.                       peg_qty         = peg_qty + absr_qty
.                    .
.
.                 end. /* if not available absr_det */
.
.                 else
.                 if available absr_det
.                    and input absr_qty = 0 then
.                 do:
.                    assign
.                       schd_all_qty  = max(schd_all_qty - absr_qty,0)
.                       prior_all_qty = schd_all_qty
.                       peg_qty       = max(peg_qty - absr_qty,0).
.
.                    delete absr_det.
.                 end.
.
.                 else
.                 if available absr_det then
.                 assign
.                    schd_all_qty  = schd_all_qty - absr_qty + input absr_qty
.                    prior_all_qty = schd_all_qty
.                    peg_qty       = peg_qty - absr_qty + input absr_qty
.                    absr_qty.
.
.              end. /* absr_qty entered */
.*K02T*        REARRANGE CODE - END */

            end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* repeat with frame peg-2 */

         end. /* MAIN: do transaction */

/*K214*/ close query q_schd_det.

/*K02F*/ hide frame peg-1 no-pause.
/*K02F*/ hide frame peg-2 no-pause.

/*K214*/ PROCEDURE p-openqty:

/*K214*/ /* THIS PROCEDURE CALCULATES THE OPEN QUANTITY FOR SCHEDULE */
/*K214*/ /* DETAIL LINES                                             */

/*K214*/    item_all_qty = 0.

/*K214*/    if not so_mstr.so_cum_acct then
/*K214*/       for each ship_line
/*K214*/          fields(abs_fa_lot abs_gwt abs_id abs_line abs_loc abs_lotser
/*K214*/                 abs_nwt abs_order abs_par_id abs_qty abs_ref
/*K214*/                 abs_shipfrom abs_site abs_vol abs_vol_um abs_wt_um
/*K214*/                 abs__qad02)
/*K214*/          where ship_line.abs_shipfrom  = abs_mstr.abs_shipfrom
/*K214*/            and ship_line.abs_par_id    = abs_mstr.abs_par_id
/*K214*/            and ship_line.abs_order     = abs_mstr.abs_order
/*K214*/            and ship_line.abs_line      = abs_mstr.abs_line
/*K214*/          no-lock:
/*K214*/          for each absr_det
/*K214*/             fields(absr_cnfrmd absr_date absr_id absr_interval
/*K214*/                    absr_line absr_nbr absr_qty absr_reference
/*K214*/                    absr_rlse_id absr_shipfrom absr_ship_id
/*K214*/                    absr_time absr_type)
/*K214*/             where absr_det.absr_shipfrom   = ship_line.abs_shipfrom
/*K214*/               and absr_det.absr_id         = ship_line.abs_id
/*K214*/               and absr_det.absr_type       = schd_det.schd_type
/*K214*/               and absr_det.absr_nbr        = schd_det.schd_nbr
/*K214*/               and absr_det.absr_line       = schd_det.schd_line
/*K214*/               and absr_det.absr_rlse_id    = schd_det.schd_rlse_id
/*K214*/               and absr_det.absr_date       = schd_det.schd_date
/*K214*/               and absr_det.absr_time       = schd_det.schd_time
/*K214*/               and absr_det.absr_interval   = schd_det.schd_interval
/*K214*/               and absr_det.absr_reference  = schd_det.schd_reference
/*K214*/               and not absr_cnfrmd
/*K214*/             no-lock:

/*K214*/             item_all_qty = item_all_qty + absr_qty.

/*K214*/          end. /* FOR EACH ABSR_DET */
/*K214*/       end. /* FOR EACH SHIP_LINE */

/*K214*/       assign
/*K214*/          open_qty = max(schd_discr_qty -
/*K214*/                         schd_all_qty - schd_ship_qty, 0)
/*K214*/          open_qty = if (schd_all_qty - item_all_qty +
/*K214*/                         schd_ship_qty) /
/*K214*/                         schd_discr_qty * 100 >= ship_cmplt
/*K214*/                         then 0
/*K214*/                         else open_qty
/*K214*/          open_qty = if so_cum_acct
/*K214*/                        then max(schd_cum_qty -
/*K214*/                                 sod_det.sod_cum_qty[1] -
/*K214*/                                 cum_open_qty - cum_all_qty -
/*K214*/                                 schd_all_qty,0)
/*K214*/                        else open_qty.

/*K214*/ END PROCEDURE. /* END PROCEDURE */
